/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.krArmor;

import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import ru.jSky.JSkyGlobal;
import ru.jSky.generator.adapter.AutoSelectionItemsGenerator;
import ru.jSky.interfaces.Armor;

/**
 *
 * @author Rakev
 */
public abstract class AbstractEnchantmenterFactory {

    public AutoSelectionItemsGenerator<Armor> create() {
        try {
            EnchantmentGeneratorBuilder enchantmenter = new EnchantmentGeneratorBuilder();
            enchantmenter.addEnchantmentEdidRegex(getImposedEnchantmentEdidRegexs());
            Map<String, String[]> permitRule = createEnchantmentPermitRule();
            for (String enchantmentRegex : permitRule.keySet()) {
                enchantmenter.addEnchantmentEdidRegexToPermitedKeywordRegexLink(enchantmentRegex, permitRule.get(enchantmentRegex));
            }
            Map<String, String[]> forbidenRule = createEnchantmentForbidenRule();
            for (String enchantmentRegex : forbidenRule.keySet()) {
                enchantmenter.addEnchantmentEdidRegexToPermitedKeywordRegexLink(enchantmentRegex, forbidenRule.get(enchantmentRegex));
            }
            Map<String, String> edidRegexToNameAppendixLink = JSkyGlobal.getInstance().getRecoder().recode(createEdidRegexToNameAppendixLink());
            enchantmenter.addEnchantmentEdidRegexToNameAppendixLink(edidRegexToNameAppendixLink);
            enchantmenter.addEnchantmentEdidRegexToLevelingName(getEdidRegexToLevelingName());
            return enchantmenter.build();
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(AbstractEnchantmenterFactory.class.getName()).log(Level.SEVERE, null, ex);
            IllegalStateException newEx = new IllegalStateException("UnsupportedEncodingException");
            newEx.addSuppressed(ex);
            throw newEx;
        }
    }

    public String getBaseArmorEdidRegex() {
        StringBuilder totalRegex = new StringBuilder();
        for (String baseRegex : getBaseArmorEdidRegexs()) {
            totalRegex.append("|(" + baseRegex + ")");
        }
        totalRegex.deleteCharAt(0);
        return totalRegex.toString();
    }

    protected abstract String[] getBaseArmorEdidRegexs();

    protected abstract String[] getImposedEnchantmentEdidRegexs();

    protected abstract Map<String, String[]> createEnchantmentPermitRule();

    protected abstract Map<String, String[]> createEnchantmentForbidenRule();

    protected abstract Map<String, String> createEdidRegexToNameAppendixLink();

    protected abstract String[] getEdidRegexToLevelingName();
}
